package com.aspose.cells.a.d;

import com.aspose.cells.ImageOrPrintOptions;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
import javax.imageio.ImageIO;

public class zbo {
   private static boolean a = true;
   private static boolean b = true;

   public static void a(BufferedImage var0, ImageOrPrintOptions var1, OutputStream var2) throws Exception {
      Object var3 = null;
      if (a) {
         a = false;

         try {
            var3 = Class.forName("com.sun.image.codec.jpeg.JPEGCodec").getMethod("createJPEGEncoder", OutputStream.class).invoke((Object)null, var2);
         } catch (Throwable var8) {
            b = false;
         }
      } else if (b) {
         var3 = Class.forName("com.sun.image.codec.jpeg.JPEGCodec").getMethod("createJPEGEncoder", OutputStream.class).invoke((Object)null, var2);
      }

      if (b) {
         Class var4 = Class.forName("com.sun.image.codec.jpeg.JPEGImageEncoder");
         Object var5 = var4.getMethod("getDefaultJPEGEncodeParam", BufferedImage.class).invoke(var3, var0);
         Class var6 = Class.forName("com.sun.image.codec.jpeg.JPEGEncodeParam");
         float var7 = 1.0F;
         if (var1 != null) {
            var7 = (float)var1.getQuality() / 100.0F;
         }

         var6.getMethod("setQuality", Float.TYPE, Boolean.TYPE).invoke(var5, var7, false);
         if (var1 != null) {
            var6.getMethod("setDensityUnit", Integer.TYPE).invoke(var5, var6.getField("DENSITY_UNIT_DOTS_INCH").getInt((Object)null));
            var6.getMethod("setXDensity", Integer.TYPE).invoke(var5, var1.getHorizontalResolution());
            var6.getMethod("setYDensity", Integer.TYPE).invoke(var5, var1.getVerticalResolution());
         }

         var4.getMethod("setJPEGEncodeParam", var6).invoke(var3, var5);
         var4.getMethod("encode", BufferedImage.class).invoke(var3, var0);
      } else {
         ImageIO.write(var0, "jpeg", var2);
      }

      var2.flush();
   }
}
